<!--用户列表页面-->
<template>
  <div class="common-containar draft">
    <div class="pageOther-container">
      <span class="first">系统管理 / 账户列表</span>
      <div class="content">
        <!--查询条件 开始-->
        <div ref="topHeight">
          <el-row>
            <el-form :inline="true" class="demo-form-inline addData searchForm line-searchForm">
              <el-row>
                <el-col class="search-input">
                  <el-form-item label="" class="AllCgBtm_Border">
                    <el-input v-model="form.name" placeholder="请输入用户名" @keyup.enter.native="searchHandle()"></el-input>
                  </el-form-item>
                    <el-button class="btnSearch" type="primary" size="small" @click="searchHandle()">查询</el-button>
                    <el-button icon="el-icon-plus" class="right btnHost addBtn" size="small" type="btn-search" @click="addUser" v-if="$store.state.currentJur.isAdd">创建用户</el-button>
                </el-col>
              </el-row>
            </el-form>
          </el-row>
        </div>
        <!--查询条件 结束-->
        <!--表格数据 开始-->
        <el-table 
          :height="height"
          :data="tableData"
          style="width:100%" 
          tooltip-effect="dark"
          v-loading="loading"
        >
          <el-table-column type="selection" width="55" align="left"></el-table-column>
          <el-table-column prop="account" label="账号" width="100" align="left"></el-table-column>
          <el-table-column prop="username" label="用户名" width="200" align="left"></el-table-column>
          <el-table-column prop="userGroup" label="集团" width="160" align="left"></el-table-column>
          <el-table-column prop="roleName" label="个人角色" width="160" align="left"></el-table-column>
          <el-table-column label="审核权限" align="left">
              <template slot-scope="scope">
                  {{scope.row.auditPrimissons == 1? '是':'否'}}
              </template>
          </el-table-column>
          <el-table-column label="支付权限" align="left">
              <template slot-scope="scope">
                  {{scope.row.payPrimissons == 1? '是':'否'}}
              </template>
          </el-table-column>
          <el-table-column label="是否开启分账" align="left">
              <template slot-scope="scope">
                  {{scope.row.isFashionable == 1? '是':'否'}}
              </template>
          </el-table-column>
          <el-table-column prop="fashionableRules" label="分账规则" width="160" align="left"></el-table-column>
          <el-table-column
            prop="info"
            label="描述"
            :show-overflow-tooltip="true"
            width="150"
            align="left"
          ></el-table-column>
          <el-table-column label="启用/禁用" v-if="isJvese == 1">
            <template slot-scope="scope">
                <el-switch 
                    @change="switchChange($event,scope.row)"
                    v-model="scope.row.status == 1?true:false">
                </el-switch>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="left">
            <template slot-scope="scope">
              <el-button @click.native.prevent="updateUser(scope.row.id)" type="text" size="small" v-if="$store.state.currentJur.isEdit">编辑</el-button>
              <el-button v-if="isJvese == 1" @click.native.prevent="cusPriceHandle(scope.row.id)" type="text" size="small">权益价格</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--表格数据 结束-->
      </div>
      <!--分页-->
      <div class="pagination-container" align="right">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 50]"
          :page-size="page.per"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
    <!--详情弹框 结束-->
    <!--新增、编辑用户 开始-->
    <el-dialog class="registerModal" :title="addTitle" :visible.sync="addUserVisible">
      <el-form
        ref="addform"
        :inline="true"
        :model="addform"
        label-width="100px"
        class="demo-form-inline"
        :rules="addRules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="账号" prop="account" class="regStyle">
              <el-input v-model="addform.account" placeholder="请输入账号" :disabled="userDisabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="个人角色" prop="roleTypesId" class="regStyle">
                <el-select
                    v-model="addform.roleTypesId"
                    class="userGroup"
                    filterable clearable 
                    value-key="id"
                    placeholder="请选择个人角色">
                      <el-option 
                        v-for="(item, index) in d_role_types" 
                        :key="index"
                        :value="item.id+''"
                        :label="item.roleName"></el-option>
                </el-select>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户名" prop="storeName" class="regStyle">
              <el-input v-model="addform.storeName" placeholder="请输入用户名"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="密码" prop="password" class="regStyle">
              <el-input type="password" v-model="addform.password" placeholder="请输入密码" @input="passChange"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          
          <el-col :span="12">
            <el-form-item label="集团" prop="groupId" class="regStyle">
              <el-select
                clearable 
                v-model="addform.groupId"
                class="userGroup"
                placeholder="请选择集团"
              >
                <el-option
                  v-for="(item, index) in groupIds"
                  :key="index"
                  :value="item.id+''"
                  :label="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核权限" prop="auditPrimissons" class="regStyle">
              <el-select 
                clearable 
              class="userGroup"
                v-model="addform.auditPrimissons"
                placeholder="请选择"
              >
                <el-option
                  value="1"
                  label="是"
                ></el-option>
                <el-option
                  value="0"
                  label="否"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          
          <el-col :span="12">
            <el-form-item label="角色权限" prop="jveesId" class="regStyle">
              <el-select 
                clearable 
                v-model="addform.jveesId"
                class="userGroup"
                placeholder="请选择"
              >
                <el-option
                  v-for="(item, index) in groupjvese"
                  :key="index"
                  :value="item.id+''"
                  :label="item.jvese"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="业务人员" prop="businessPersonnel" class="regStyle" v-if="d_role_type_name != '审单or管理员' && d_role_type_name != '业务经理' && d_role_type_name != '业务人员'">
                <el-select 
                    clearable filterable
                    v-model="addform.businessPersonnel"
                    class="userGroup"
                    placeholder="请选择业务人员">
                      <el-option 
                        v-for="(item,index) in businessPersonnels" 
                        :key="index"
                        :value="item.userId+''" 
                        :label="item.username"></el-option>
                </el-select>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
         
          <el-col :span="12">
              <el-form-item label="业务经理" prop="businessManager" class="regStyle" v-if="d_role_type_name != '审单or管理员' && d_role_type_name != '业务经理'">
                <el-select 
                    clearable filterable
                    v-model="addform.businessManager"
                    class="userGroup"
                    placeholder="请选择业务经理">
                      <el-option 
                        v-for="(item,index) in businessManagers" 
                        :key="index"
                        :value="item.userId+''" 
                        :label="item.username"></el-option>
                </el-select>
              </el-form-item>
          </el-col>
           <el-col :span="12">
              <el-form-item label="代理" prop="subordinateAgent" class="regStyle" v-if="d_role_type_name != '业务人员' && d_role_type_name != '审单or管理员' && d_role_type_name != '代理' && d_role_type_name != '业务经理'">
                <el-select 
                    clearable filterable
                    v-model="addform.subordinateAgent"
                    class="userGroup"
                    placeholder="请选择代理">
                      <el-option 
                        v-for="(item,index) in subordinateAgents" 
                        :key="index"
                        :value="item.userId+''" 
                        :label="item.username"></el-option>
                </el-select>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="组合权益" prop="comPackage" label-width="110px" style="text-align:left;">
              <el-checkbox-group v-model="addform.comPackage" style="padding-left: 110px;">
                      <el-checkbox @change="val => comPackageChange(index,val)"
                      v-for="(item,index) in comPackages" 
                      :key="index"
                      :label="item.name"
                      :value="item.name"
                      v-model="item.status"></el-checkbox>
                </el-checkbox-group>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-if="addform.comPackage.includes('L')" class="cxPrimissons" label="畅行无忧权益范围" prop="cxPrimissons" label-width="110px" style="text-align:left;">
                    <el-checkbox-group v-model="addform.cxPrimissons" style="padding-left: 110px;">
                      <el-checkbox  @change="val => cx_Lchange(index, val)"
                            v-for="(item,index) in cx_L"
                            :key = "index"
                            :value="item.name"
                            :label="item.name"
                            v-model="item.status">
                      </el-checkbox>
                    </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item class="cxPrimissons" label="定制畅行无忧" prop="cusPrimissons" label-width="110px" style="text-align:left;">
                    <el-checkbox-group v-model="addform.cusPrimissons" style="padding-left: 110px;">
                      <el-checkbox  @change="val => cus_permischange(index, val)"
                            v-for="(item,index) in cus_primissons"
                            :key = "index"
                            :value="item.name"
                            :label="item.name"
                            v-model="item.status">
                      </el-checkbox>
                    </el-checkbox-group>
                    <!--<el-select
                        v-model="addform.cusPrimissons"
                        multiple
                        collapse-tags
                        style="margin-left: 20px;"
                        placeholder="请选择"
                        @change="cus_permischange">
                        <el-option
                          v-for="(item, index) in cus_primissons"
                          :key="index"
                          :label="item.name"
                          :value="item.name">
                        </el-option>
                    </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="固定权益选择"  prop="isL" class="regStyle">
              <el-select v-model="addform.isL" placeholder="请选择" class="userGroup">
                <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="导出表格权限"  prop="exeleStatus" class="regStyle">
              <el-select v-model="addform.exeleStatus" placeholder="请选择" class="userGroup">
               <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数据表格权限"  prop="dataTable" class="regStyle">
              <el-select v-model="addform.dataTable" placeholder="请选择" class="userGroup">
               <el-option label="否" value="0" ></el-option>
                <el-option label="是" value="1" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item class="ybPrimissons" label="延保保障方案" prop="ybPrimissons" label-width="110px">
                    <el-checkbox-group v-model="addform.ybPrimissons">
                        <el-checkbox label="综合保修" value="综合保修"></el-checkbox>
                        <el-checkbox label="动力总成" value="动力总成"></el-checkbox>
                        <el-checkbox label="全面保修" value="全面保修"></el-checkbox>
                    </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="补偿权限"  prop="comStandard" class="regStyle">
              <el-select v-model="addform.comStandard" placeholder="请选择" class="userGroup">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付权限" prop="payPrimissons" class="regStyle">
              <el-select 
                clearable 
                style="width:100%;"
                v-model="addform.payPrimissons"
                placeholder="请选择"
              >
                <el-option
                  value="1"
                  label="是"
                ></el-option>
                <el-option
                  value="0"
                  label="否"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="addform.comStandard == 1">
          <el-col :span="24">
            <el-col :span="4">出险补偿保服务A、B</el-col>
            <el-col :span="20">
              <table class="el-table comStandard" style="text-align:center;padding: 0 40px 10px 40px;">
                  <thead>
                    <tr>
                      <th>定损金额</th>
                      <th>补偿标准</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td>2000元<维修金额≤5000元</td>
                      <td>
                        <input v-model="addform.comStandard1" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                        <!--<el-form-item prop="comStandard1" style="width: 100%;height: 30px;margin-bottom: 0;">
                          <el-input  v-model="addform.comStandard1" placeholder="请输入补偿标准1" style="width: 100%;height: 30px;margin-bottom: 0;"></el-input>
                        </el-form-item>-->
                      </td>
                    </tr>
                    <tr>
                      <td>5000元<维修金额≤10000元</td>
                      <td>
                        <input v-model="addform.comStandard2" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                       <!-- <el-form-item prop="comStandard2" style="width: 100%;height: 30px;margin-bottom: 0;">
                          <el-input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" v-model="addform.comStandard2" type="number" min="0" placeholder="请输入补偿标准" style="width: 100%;height: 30px;margin-bottom: 0;"></el-input>
                        </el-form-item> -->
                      </td>
                    </tr>
                    <tr>
                      <td>10000<维修金额</td>
                      <td>
                        <input v-model="addform.comStandard3" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                        <!--<el-form-item prop="comStandard3" style="width: 100%;height: 30px;margin-bottom: 0;">
                          <el-input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" v-model="addform.comStandard3" type="number" min="0" placeholder="请输入补偿标准" style="width: 100%;height: 30px;margin-bottom: 0;"></el-input>
                        </el-form-item>-->
                      </td>
                    </tr>
                  </tbody>
              </table>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="4">出险补偿保服务C</el-col>
            <el-col :span="20">
              <table class="el-table comStandard" style="text-align:center;padding: 0 40px 10px 40px;">
                  <thead>
                    <tr>
                      <th>定损金额</th>
                      <th>补偿标准</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td>1000元<维修金额≤3000元</td>
                      <td>
                        <input v-model="addform.comStandardC1" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                      </td>
                      <!--
                      <el-form-item prop="comStandardC1" style="width: 100%;height: 30px;margin-bottom: 0;">
                        <el-input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" v-model="addform.comStandardC1" type="number" min="0" placeholder="请输入补偿标准" style="width: 100%;height: 30px;margin-bottom: 0;"></el-input>
                      </el-form-item>-->
                    </tr>
                    <tr>
                      <td>3000元<维修金额≤10000元</td>
                      <td>
                        <input v-model="addform.comStandardC2" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                      </td>
                    </tr>
                    <tr>
                      <td>10000元<维修金额≤30000元</td>
                      <td>
                        <input v-model="addform.comStandardC3" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                      </td>
                    </tr>
                    <tr>
                      <td>30000<维修金额</td>
                      <td>
                        <input v-model="addform.comStandardC4" placeholder="请输入补偿标准" type="number" style="border: 1px solid #DCDFE6;padding: 4px;border-radius: 4px;" />
                      </td>
                    </tr>
                  </tbody>
              </table>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
              <el-form-item label="是否开启分账" prop="isFashionable" class="regStyle">
                  <el-select clearable v-model="addform.isFashionable" placeholder="请选择" style="width:100%;" @change="validChange">
                      <el-option label="否" value="0"></el-option>
                      <el-option label="是" value="1"></el-option>
                  </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="分账规则" prop="fashionableRules" class="regStyle">
                  <el-input v-model="addform.fashionableRules" placeholder="请输入分账规则" :disabled="rulesDisabled"></el-input>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备权限" prop="equimentPermissions" class="regStyle">
              <el-select 
                clearable 
              style="width:100%;"
                v-model="addform.equimentPermissions"
                placeholder="请选择"
              >
                <el-option
                  key="1"
                  value="1"
                  label="是"
                ></el-option>
                <el-option
                  key="0"
                  value="0"
                  label="否"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
            <el-col :span="12">
              <el-form-item label="描述" prop="info"  class="regStyle">
                <el-input type="textarea" :rows="1" v-model="addform.info"></el-input>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="省份城市" prop="customAddr" class="regStyle">
                <el-cascader @change="proviceChange"
                    :options="options"
                    v-model="customAddr"
                    placeholder="请选择地区"
                    :separator="'-'"
                    size="small">
                </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目经理" prop="projectManager" class="regStyle">
                <el-input v-model="addform.projectManager" placeholder="请输入项目经理"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="运营督导" prop="operationSuper" class="regStyle">
                <el-input v-model="addform.operationSuper" placeholder="请输入运营督导"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="督导电话" prop="superPhone" class="regStyle">
                <el-input v-model="addform.superPhone" placeholder="请输入督导电话"></el-input>
            </el-form-item>
          </el-col>
          
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="营销组" prop="markGroupId" class="regStyle" v-if="markGroups && markGroups.length>0">
                <el-select clearable v-model="addform.markGroupId" placeholder="请选择" style="width:100%;">
                    <el-option v-for="(item, index) in markGroups"
                      :key = "index"
                      :label="item.groupName"
                      :value="item.id + ''"></el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="汽车品牌" prop="brand" class="regStyle" v-if="carBrands && carBrands.length>0">
                <el-select clearable v-model="addform.brand" placeholder="请选择" style="width:100%;" >
                    <el-option
                      v-for="(item, index) in carBrands" 
                      :key="index"
                      :label="item.brandName"
                      :value="item.id +''"></el-option>
                </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开户行" prop="bankofdeposit" class="regStyle">
                <el-input v-model="addform.bankofdeposit" placeholder="请输入开户行"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收款账号" prop="collection" class="regStyle">
                <el-input v-model="addform.collection" placeholder="请输入收款账号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
       <div slot="footer" class="dialog-footer">
          <el-button @click="addUserVisible=false">取 消</el-button>
          <el-button type="primary" :loading="submitLoading" @click="addUserSubmit(addTitle== '新增用户' ? '/user/insertUser' : '/user/updateUser')">确 定</el-button>
        </div>

    </el-dialog>
    <!--新增、编辑用户 结束-->


    <el-dialog title="权益价格" :visible.sync="priceVisible" width="50%">
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick" style="padding: 0 40px;">
          <el-tab-pane label="定制权益价格" name="first"></el-tab-pane>
          <el-tab-pane label="畅行权益价格" name="second"></el-tab-pane>
        </el-tabs>
        <el-row v-if="activeName == 'first'">
          <el-form ref="priceform" :inline="true" :model="priceform" label-width="80px">
            <el-row v-if="priceTableData_cus && priceTableData_cus.length > 0">
              <el-row>
                <el-col :span="12" v-for="(item, index) in priceTableData_cus" :key="index"
                  v-if="item.name != '轮胎保障服务' && item.name != '组合权益'">
                  <el-col class="priceTitle">{{item.name}}:</el-col>
                  <!-- :prop="'items.' + index + '.price'"-->
                  <el-form-item label="价格" >
                      <el-input v-model="item.price" placeholder="请输入价格"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>  <!--轮胎保障-->
                <el-col :span="24" v-for="(item, ind) in priceTableData_cus" v-if="item.name == '轮胎保障服务'"  :key="ind">
                  <el-col class="priceTitle">{{item.name}}:
                    <el-button class="right" @click="addNewTypes">新增车型</el-button>
                  </el-col>
                  <el-table class="priceTable"
                    v-loading="priceLoading"
                    :data="item.res"
                    height="200"
                    style="width: 100%;padding: 0 40px;">
                    <el-table-column
                      prop="name"
                      label="车型">
                    </el-table-column>
                    <el-table-column
                      prop="price"
                      label="价格">
                      <template slot-scope="scope">
                        <el-input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" type="number" min="0" placeholder="请输入价格" v-model="scope.row.price" />
                      </template>
                    </el-table-column>
                    <el-table-column v-if="isJvese == 1"
                      label="操作">
                      <template slot-scope="scope">
                        <el-button
                          @click.native.prevent="priceDeleteRow(scope.$index, scope.row)"
                          type="text"
                          size="small">
                          移除
                        </el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-col>
              </el-row>
              <el-row>  <!--组合权益-->
                <el-col :span="24"  v-for="(item, i) in priceTableData_cus" v-if="item.name == '组合权益'"  :key="i">
                  <el-col class="priceTitle" style="padding: 30px 40px 10px 40px;">{{item.name}}:
                    <el-button class="right" @click="addNewTypes_group()">新增组合权益</el-button>
                  </el-col>
                  <el-table class="priceTable"
                    v-loading="priceLoading_group"
                    :data="item.res"
                    height="200"
                    style="width: 100%;padding: 0 40px;">
                    <el-table-column
                      prop="name"
                      label="权益范围">
                    </el-table-column>
                    <el-table-column
                      prop="price"
                      label="价格">
                      <template slot-scope="scope">
                        <el-input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" type="number" min="0" placeholder="请输入价格" v-model="scope.row.price" />
                      </template>
                    </el-table-column>
                    <el-table-column v-if="isJvese == 1"
                      label="操作">
                      <template slot-scope="scope">
                        <el-button v-if="scope.row.name.indexOf('轮胎') != -1 || scope.row.name.indexOf('超享换新') != -1"
                          @click.native.prevent="lookForHandle_cus(scope.$index, scope.row)"
                          type="text"
                          size="small">
                          查看
                        </el-button>
                        <el-button
                          @click.native.prevent="priceGroupDeleteRow(scope.$index, scope.row)"
                          type="text"
                          size="small">
                          移除
                        </el-button>
                      </template>

                    </el-table-column>
                  </el-table>
                </el-col>
              </el-row>
            </el-row>
          </el-form>
        </el-row>
        <el-row v-else>
          <el-col :span="24">
            <el-col class="priceTitle" style="padding: 20px 40px;">
              <el-button class="right" @click="addNewTypes_tab">新增定制权益</el-button>
            </el-col>
            <el-table class="priceTable"
              v-loading="priceLoading_cx"
              :data="priceTableData_cx"
              height="200"
              style="width: 100%;padding: 0 40px;">
              <el-table-column
                prop="name"
                label="定制权益范围">
              </el-table-column>
              <el-table-column 
                width="120"
                prop="price"
                label="价格">
                <template slot-scope="scope">
                  <el-input type="text" placeholder="请输入价格" v-model="scope.row.price" />
                </template>
              </el-table-column>
              <el-table-column v-if="isJvese == 1"
                label="操作">
                <template slot-scope="scope">

                  <!--<el-button 
                    @click.native.prevent="rulesHandle_cx(scope.row)"
                    type="text"
                    size="small">
                    新增规则
                  </el-button>-->
                  <el-button 
                    @click.native.prevent="lookForHandle_cx(scope.$index, scope.row)"
                    type="text"
                    size="small">
                    查看
                  </el-button>
                  <el-button
                    @click.native.prevent="priceTabDeleteRow_cx(scope.$index, scope.row)"
                    type="text"
                    size="small">
                    移除
                  </el-button>
                </template>

              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
        <div slot="footer" class="dialog-footer" v-if="activeName == 'first'">
            <el-button @click="priceVisible=false">取 消</el-button>
            <el-button type="primary" @click="priceSubmit_cus">确 定</el-button>
        </div>
        <div slot="footer" class="dialog-footer" v-else>
            <el-button @click="priceVisible=false">取 消</el-button>
            <el-button type="primary" @click="priceSubmit_cx">确 定</el-button>
        </div>
    </el-dialog>


    <!--轮胎类型添加  start-->
    <el-dialog title="新增车型" :visible.sync="priceTypeVisible" width="50%" :close-on-click-modal="false" :show-close="false">
      <el-form ref="priceTypeform" :inline="true" :model="priceTypeform" label-width="60px">
          <el-row :gutter="24" v-for="(item, index) in priceTypeform.items" :key="index">
            <el-col :span="10">
              <el-form-item label="车型" :prop="'items.' + index + '.name'" :rules="{required: true, message: '车型不能为空', trigger: 'blur'}">
                  <el-input v-model="item.name" placeholder="请输入车型"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="价格" :prop="'items.' + index + '.price'" :rules="[{required: true, message: '价格不能为空', trigger: 'blur'},{ pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入数字,可保留两位小数' }]">
                  <el-input v-model="item.price" placeholder="请输入价格"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2" v-if="priceTypeform.items.length !== 1">
              <i @click="removePriceTypeForm(item)" style="font-size:26px;cursor:pointer;" class="el-icon-delete"></i>
            </el-col>
            <el-col :span="2" >
              <el-button @click="onInputAdd" size="mini" class="el-icon-plus"></el-button>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--resetForm('priceTypeform');-->
				<el-button @click="priceTypeVisible=false">取 消</el-button>
        <el-button type="primary" @click="priceTypeSubmit(carType)">确 定</el-button>
			</div>
    </el-dialog>
    <!--轮胎类型台加   end-->
    <!--轮胎类型添加  start-->
    <el-dialog title="新增组合权益" :visible.sync="priceTypeVisible_group" width="50%" :close-on-click-modal="false" :show-close="false">
      <el-form ref="priceTypeform_group" :inline="true" :model="priceTypeform_group" label-width="60px">
          <el-row :gutter="24" v-for="(item, index) in priceTypeform_group.items" :key="index">
            <el-col :span="10">
              <el-form-item label="权益" :prop="'items.' + index + '.name'" :rules="{required: true, message: '权益不能为空', trigger: 'blur'}">
                  <el-input v-model="item.name" placeholder="请输入权益"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="价格" :prop="'items.' + index + '.price'" :rules="[{required: true, message: '价格不能为空', trigger: 'blur'},{ pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入数字,可保留两位小数' }]">
                  <el-input v-model="item.price" placeholder="请输入价格"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2" v-if="priceTypeform_group.items.length !== 1">
              <i @click="removePriceTypeForm_group(item)" style="font-size:26px;cursor:pointer;" class="el-icon-delete"></i>
            </el-col>
            <el-col :span="2" >
              <el-button @click="onInputAdd_group" size="mini" class="el-icon-plus"></el-button>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--resetForm('priceTypeform_group');-->
				<el-button @click="priceTypeVisible_group=false">取 消</el-button>
        <el-button type="primary" @click="priceTypeSubmit_group">确 定</el-button>
			</div>
    </el-dialog>
    <!--轮胎类型台加   end-->
    <!--畅行权益价格 --查看 start -->
    <el-dialog title="权益规则" :visible.sync="dialogTableVisible_cx">
      <el-row>
        <el-col :span="12" align="left"> <a style="color: #f00;">{{gropuTableData_cx.name}}</a> </el-col>
        <el-col :span="12"><el-button class="right" @click="rulesHandle_cx">新增规则</el-button></el-col>
      </el-row>
      <el-table :data="gropuTableData_cx.res">
        <!--<el-table-column property="name" label="权益范围" width="150"></el-table-column>-->
        <el-table-column property="price" label="价格"></el-table-column>
        <el-table-column property="rules" label="规则">
          <template slot-scope="scope">
            <el-input type="text" placeholder="请输入规则" v-model="scope.row.rules" />
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="gropuTableDelRow_cx(scope.$index, scope.row)"
              type="text"
              size="small">
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
          <el-button @click="dialogTableVisible_cx=false">关 闭</el-button>
      </div>
    </el-dialog>
    <!--畅行规则查看 end -->

    <!--定制权益价格-组合权益 查看 start -->
    <el-dialog title="权益范围" :visible.sync="dialogTableVisible_cus">
      <el-row>
        <el-col :span="12" align="left"> <a style="color: #f00;">{{gropuTableData_cus.name}}</a> </el-col>
        <el-col :span="12"><el-button class="right" @click="addGroupRow">新增车型</el-button></el-col>
      </el-row>
      <el-table :data="gropuTableData_cus.res">
        <el-table-column property="name" label="权益范围" width="150"></el-table-column>
        <el-table-column property="price" label="价格" >
          <template slot-scope="scope">
            <el-input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')" type="number" min="0" placeholder="请输入价格" v-model="scope.row.price" />
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="gropuTableDelRow(scope.$index, scope.row)"
              type="text"
              size="small">
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
				<el-button @click="dialogTableVisible_cus=false">关 闭</el-button>
			</div>
    </el-dialog>
    <!--定制-组合权益查看 end -->

    <!--定制权益新增 start-->
    <el-dialog title="新增定制权益" :visible.sync="priceTypeVisible_tab" width="50%" :close-on-click-modal="false" :show-close="false">
      <el-form ref="priceTypeform_tab" :inline="true" :model="priceTypeform_tab" label-width="60px">
          <el-row :gutter="24" v-for="(item, index) in priceTypeform_tab.items" :key="index">
            <el-col :span="10">
              <el-form-item label="权益" :prop="'items.' + index + '.name'" :rules="{required: true, message: '权益不能为空', trigger: 'blur'}">
                  <el-input v-model="item.name" placeholder="请输入权益"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="价格" :prop="'items.' + index + '.price'" :rules="[{required: true, message: '价格不能为空', trigger: 'blur'},{ pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入数字,可保留两位小数' }]">
                  <el-input v-model="item.price" placeholder="请输入价格"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2" v-if="priceTypeform_tab.items.length !== 1">
              <i @click="removePriceTypeForm_tab(item)" style="font-size:26px;cursor:pointer;" class="el-icon-delete"></i>
            </el-col>
            <el-col :span="2" >
              <el-button @click="onInputAdd_tab" size="mini" class="el-icon-plus"></el-button>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--resetForm('priceTypeform_tab');-->
				<el-button @click="priceTypeVisible_tab=false">取 消</el-button>
        <el-button type="primary" @click="priceTypeSubmit_tab">确 定</el-button>
			</div>
    </el-dialog>
    <!--定制权益新增 end-->
    <!--规则新增 start-->
    <el-dialog title="新增规则" :visible.sync="ruleVisible_tab" width="50%" :close-on-click-modal="false" :show-close="false">
      <el-form ref="ruleForm_tab" :inline="true" :model="ruleForm_tab" label-width="60px">
          <el-row :gutter="24" v-for="(item, index) in ruleForm_tab.items" :key="index">
            <el-col :span="10">
              <el-form-item label="规则" :prop="'items.' + index + '.rules'" :rules="{required: true, message: '规则不能为空', trigger: 'blur'}">
                  <el-input v-model="item.rules" placeholder="请输入规则"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <!--<el-form-item label="价格" :prop="'items.' + index + '.price'" :rules="[{required: true, message: '价格不能为空', trigger: 'blur'},{ pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入数字,可保留两位小数' }]">-->
              <el-form-item label="价格" :prop="'items.' + index + '.price'" :rules="[{required: true, message: '价格不能为空', trigger: 'blur'},{ pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入数字,可保留两位小数' }]">
                  <el-input v-model="item.price" placeholder="请输入价格"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2" v-if="ruleForm_tab.items.length !== 1">
              <i @click="removeRuleForm_tab(item)" style="font-size:26px;cursor:pointer;" class="el-icon-delete"></i>
            </el-col>
            <el-col :span="2" >
              <el-button @click="onInputAdd_rule" size="mini" class="el-icon-plus"></el-button>
            </el-col>
          </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--resetForm('ruleForm_tab');-->
				<el-button @click="ruleVisible_tab=false">取 消</el-button>
        <el-button type="primary" @click="ruleSubmit_tab">确 定</el-button>
			</div>
    </el-dialog>
    <!--规则新增 end-->
  </div>
</template>

<script>
import options from '@/assets/js/country-level2-data.js';
import crypto from 'crypto';
export default {
  name: "register",
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.addform.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      cx_L: [{name:'车辆全损 换新服务',status:false}, 
      {name:'出险补偿保障服务',status:false}, {name:'出险补偿保障服务B',status:false},{name:'出险补偿保障服务C',status:false},
      {name: '财产无忧保障服务',status:false},{name: '驾乘无忧 保障服务',status:false},
      {name: '刮蹭无忧服务',status:false},{name: '轮胎保障服务',status:false},
      {name: '还款无忧 保障服务',status:false},{name: '代步车费用补偿服务',status:false},
      {name: '超享换服务',status:false},{name: '驾驶人意外保障服务',status:false}],
      //  定制畅行无忧
      cus_primissons: [{name:'财产无忧保障服务',status:false},{name:'财产无忧PLUS保障服务',status:false},
      {name:'轮胎保障服务',status:false},{name:'出险补偿保障服务',status:false},{name:'车辆全损 换新服务',status:false},
      {name: '超享换新服务',status:false}], 
      activeName: 'first',
      priceId:'',ruleId: '',
      isJvese: localStorage.getItem('jvese'),
      carBrands: [],  // 汽车品牌
      markGroups: [], // 营销组
      options: options,customAddr:'',   //  省市
      comPackages:[{status:false,name:'A'},{status:false,name:'A1'},{status:false,name:'A2'},
      {status:false,name:'A3'},{status:false,name:'B'},{status:false,name:'B1'},{status:false,name:'B2'},
      {status:false,name:'B3'},{status:false,name:'C'},{status:false,name:'C1'},{status:false,name:'C2'},
      {status:false,name:'C3'},{status:false,name:'L'}],
      monry:'', //  定损金额
      d_role_types: [], //个人角色
      d_role_type_name: '',
      businessPersonnels:[],   //业务人员
      businessManagers:[],     // 业务受理
      subordinateAgents:[],    //代理人员
      height: 'calc(100% - 50px)',rulesDisabled:true,
      loading: false,userDisabled:false,
      tableData: [], //查询列表
      total: 0, //总条数默认为0
      currentPage: 1, //当前页数默认为1
      page: {
        //分页信息
        per: 10,
        page: 1
      },
      form: {
        //表单数据
        time_begin: "",
        time_end: "",
        name: "",
        order_id: ""
      },
      gropuTableData_cus:{}, dialogTableVisible_cus: false, //定制-组合权益查看
      gropuTableData_cx:{}, dialogTableVisible_cx: false, //畅行-规则查看
      detail: {
        //详情弹框
        tv_msg: {},
        contract_msg: {}
      },
      addUserVisible: false, //新增弹框默认不显示
      priceVisible: false,priceTypeVisible:false,priceTypeArry:[],priceLoading:false,carType:'',carTypeIndex: '',carTypeIndex_cx:'',  //  区分新增车型是轮胎还是组合
      priceTypeVisible_group:false,priceLoading_group:false,priceTypeVisible_tab:false,priceLoading_cx:false,
      ruleVisible_tab:false,ruleVisible_tab:false,
      developmentLists:[],
      addform: {
        account: "",
        storeName: "",
        password: "",
        jveesId: "",
        auditPrimissons:'0',
        payPrimissons: '',equimentPermissions:'',
        groupId: "",
       // userGroup: "",
        info: "",
        cxPrimissons: [],cusPrimissons:[],
        ybPrimissons: [],
        //development_id:'', //  开发经理
        isFashionable: '0',
        fashionableRules: '',
        roleTypesId: '', //个人角色
        businessPersonnel:'',    //业务人员
        subordinateAgent:'',     //代理人员
        businessManager:'',    //业务经理
        comPackage: [],    //  A-L
        
        comStandard: '0',   // 补偿权限
        exeleStatus: '0',    //  导出表格权限
        dataTable: '0',    //  数据表格
        comStandard1: '',comStandard2:'',comStandard3:'',                        //  补偿标准AB
        comStandardC1: '',comStandardC2:'',comStandardC3:'',comStandardC4:'',   //  补偿标准C
        brand:'', // 品牌
        projectManager: '',  //项目经理
        operationSuper: '',  //运营督导
        superPhone: '',  //督导电话
        markGroupId: '', //营销组
        collection:'',  //  收款账号
        bankofdeposit:'',  //  开户行
        isL: '0',

      },
      priceform: {      //  单个权益价格
        price: "",
      },
      priceTypeform:{   //  新增车型的权益/价格
        items: [{
            price: '',
            name: '',
            res: []
          }
        ]
      },
      priceTypeform_group:{ //  组合权益新增的权益/价格
        items: [{
            price: '',
            name: '',
            res: []
          }
        ]
      },
      priceTypeform_tab:{
        items: [{
            price: '',
            name: '',
            res: []
          }
        ]
      },
      ruleForm_tab:{
        items: [{
            name: '',
            price: '',
            rules: '',
            res: []
          }
        ]
      },
      groupjvese: [
        // { id: "p", jvese_name: "普通用户" },
        // { id: "g", jvese_name: "管理员" }
      ],
      addRules: {
        account: [
          { required: true, message: "请输入账号", trigger: "blur" }
        ],
        storeName: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 10, message: "密码长度为3-10位", trigger: "blur" }
        ],
        jvese: [{ required: true, message: "请输入角色", trigger: "blur" }],
        groupId: [{ required: true, message: "请选择集团", trigger: "blur" }],
        auditPrimissons: [{ required: true, message: "请选择审核权限", trigger: "blur" }],
        payPrimissons: [{ required: true, message: "请选择支付权限", trigger: "blur" }],
        equimentPermissions: [{ required: true, message: "请选择设备权限", trigger: "blur" }],
        isFashionable: [{ required: true, message: "请选择是否开启分账", trigger: "change" }],
        
        roleTypesId:[{ required: true, message: "请选择个人角色", trigger: "blur" }],
        
        comPackage:[{ required: true, message: "请选择组合权益", trigger: "change" }],
        jveesId:[{ required: true, message: "请选择角色权限", trigger: "change" }],
        comStandard1: [
          {
            pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: '请保留两位小数'
          }
        ]
      },
      priceTableData_cus:[],priceTableData:[],priceTableData_group:[],priceTableData_cx:[],
      groupIds: [], //集团
      addTitle: "新增用户",submitLoading:false,
      updateUserId: "", //编辑id
      nextPage:''
    };
  },
  methods: {
    getmd5(pwd){
				var md5 = crypto.createHash("md5");
				md5.update(pwd);
				var password = md5.digest('hex');
				return password;
			},
    handleClick(tab, event) {
      const This_ = this
      This_.priceLoading_cx = true;
        if(This_.activeName == 'second') {    //  畅行权益价格
          This_.cxPriceHandle(This_.priceId);
        } else if(This_.activeName == 'first') {
          This_.cusPriceHandle(This_.priceId);    //  定制权益价格
        };
      },
    proviceChange() { //  省市
      this.addform.provinces = this.customAddr[0];
      this.addform.citys = this.customAddr[1];
    },
    //  轮胎保障服务-新增车型
    addNewTypes() {
      this.carType = '轮胎保障服务';
      this.priceTypeVisible = true;
      this.priceTypeform.items = [{price: '',name: '',res:[]}];
    },
    addNewTypes_group(){
      
      this.priceTypeVisible_group = true;
      this.priceTypeform_group.items = [{price: '',name: '',res:[]}];
    },
    addNewTypes_tab() {     //  tab切换定制组织权益
      this.priceTypeVisible_tab = true;
      this.priceTypeform_tab.items = [{price: '',name: '',res:[]}];
    },
    onInputAdd() {
      this.priceTypeform.items.push({
        name:'',
        price: '',
        res: [],
        //key: Date.now()
        })
    },
    onInputAdd_group() {
      this.priceTypeform_group.items.push({
        name:'',
        price: '',
        res:[],
        //key: Date.now()
        })
    },
    onInputAdd_tab() {
      this.priceTypeform_tab.items.push({
        name:'',
        price: '',
        res:[],
        key: Date.now()
      })
    },
    onInputAdd_rule() {
      this.ruleForm_tab.items.push({
        name:'',
        rules:'',
        price: '',
        res: [],
       // key: Date.now()
      })
    },
    removePriceTypeForm(item) {
      var index = this.priceTypeform.items.indexOf(item)
			if (index !== -1) {
				this.priceTypeform.items.splice(index, 1)
			}  
    },
    removePriceTypeForm_group(item) {
      var index = this.priceTypeform_group.items.indexOf(item)
			if (index !== -1) {
				this.priceTypeform_group.items.splice(index, 1)
			}  
    },
    removePriceTypeForm_tab(item) {
      var index = this.priceTypeform_tab.items.indexOf(item)
			if (index !== -1) {
				this.priceTypeform_tab.items.splice(index, 1)
			}  
    },
    removeRuleForm_tab(item) {
      var index = this.ruleForm_tab.items.indexOf(item)
			if (index !== -1) {
				this.ruleForm_tab.items.splice(index, 1)
			}  
    },
    //重置事件
		resetForm(formName) {
			this.$refs[formName].resetFields();
		},
    priceTypeSubmit(type) {     //  新增车型提交
      const This = this;
      this.$refs.priceTypeform.validate(valid => {
        if (valid) {
          const lists = This.priceTypeform.items;   //  新增车型的数组
          var index = This.priceTableData_cus.findIndex(item => item.name == type);
          if (type == '轮胎保障服务') {
            This.priceTableData_cus[index].res = This.priceTableData_cus[index].res.concat(lists);
          } else {
            This.priceTableData_cus[index].res[This.carTypeIndex].res = This.priceTableData_cus[index].res[This.carTypeIndex].res.concat(lists);
          };
          This.priceTypeVisible = false;
        }else{
          return false;
        }
      })
    },
    priceTypeSubmit_group() {
      const This = this
      this.$refs.priceTypeform_group.validate(valid => {
        if (valid) {
            const list = This.priceTypeform_group.items;    //  新增组合权益的数组
            var index = This.priceTableData_cus.findIndex(item => item.name == "组合权益");
            This.priceTableData_cus[index].res = This.priceTableData_cus[index].res.concat(list);
            This.priceTypeVisible_group = false;
        }else{
          return false;
        }
      })
    },
    priceTypeSubmit_tab() {
      const This = this
      this.$refs.priceTypeform_tab.validate(valid => {
        if (valid) {
          const list = This.priceTypeform_tab.items;
          this.priceTableData_cx = this.priceTableData_cx.concat(list);
          this.priceTypeVisible_tab = false;
        }else{
          return false;
        }
      })
    },
    ruleSubmit_tab() {
      const This = this
      this.$refs.ruleForm_tab.validate(valid => {
        if (valid) {
            const list = This.ruleForm_tab.items;
            This.priceTableData_cx[This.carTypeIndex_cx].res = This.priceTableData_cx[This.carTypeIndex_cx].res.concat(list);
            This.ruleVisible_tab = false;
        }else{
          return false;
        }
      })
    },
    lookForHandle_cx(index, row) {    //  畅行-查看二级规则
      this.dialogTableVisible_cx = true;
      this.carTypeIndex_cx = index;
      this.gropuTableData_cx = this.priceTableData_cx[index];
    },

    lookForHandle_cus(index, row) {     //  定制组合权益查看
        var groupIndex = this.priceTableData_cus.findIndex(item => item.name == "组合权益");
        this.gropuTableData_cus = this.priceTableData_cus[groupIndex].res[index];
        this.carTypeIndex = index;
        this.dialogTableVisible_cus = true;
    },
    addGroupRow() {      //  组合权益有轮胎-超享换进行新增
      this.carType = '组合权益';
      this.priceTypeVisible = true;
      this.priceTypeform.items = [{price: '',name: '',res:[]}];
    },
    rulesHandle_cx(row) {
      this.ruleVisible_tab = true;
      this.ruleId = row.id;
      this.ruleForm_tab.items = [{name: '',price: '',rules: '', res:[]}];
    },
    priceDeleteRow(removeIndex, row) {   //  删除车型
      var index = this.priceTableData_cus.findIndex(item => item.name == "轮胎保障服务");
      this.priceTableData_cus[index].res.splice(removeIndex, 1);
    },
    priceGroupDeleteRow(removeIndex, row) {  //  删除组合权益列表
        var index = this.priceTableData_cus.findIndex(item => item.name == "组合权益");
        this.priceTableData_cus[index].res.splice(removeIndex, 1);
    },
    gropuTableDelRow(removeIndex, row) {     //  组合权益查看列表删除
      var index = this.priceTableData_cus.findIndex(item => item.name == "组合权益");
      this.priceTableData_cus[index].res[this.carTypeIndex].res.splice(removeIndex, 1);
    },
    gropuTableDelRow_cx(removeIndex, row) {   //  移除权益规则
      this.priceTableData_cx[this.carTypeIndex_cx].res.splice(removeIndex, 1);
    },
    priceTabDeleteRow_cx(index, row) {  //  删除畅行权益价格列表
      this.priceTableData_cx.splice(index, 1);
    },
    switchChange(val, item) {
      const self__ = this
      const info = val == true?'启用':'禁用';
      this.$http.get(this.GLOBAL.REQUESTURL+"/user/updateStatus",{
        id: item.id,
        status: val == true?1:0
      })
      .then(res => {
        if(res.code == 200) {
          self__.$message.success(res.msg)
          self__.initData()
        } else {
          self__.$message.info(res.msg)
        }
      }).catch(err => {
        self__.$message.error(info + '失败')
      });
    },
    carBrand() {  //  获取所有汽车品牌
      const self_ = this
      self_.$http.get(self_.GLOBAL.REQUESTURL +"/user/getCarList")
      .then(res => {
        self_.carBrands = res.data;
      }).catch(err => {
        self_.carBrands = []
      })
    },
    markGroupsHandle() {    //  获取所有营销组
				var $this = this; 
        this.$http.get(this.GLOBAL.REQUESTURL +"/user/getMarkGroupList")
        .then(res => {
            $this.markGroups = res.data;
        }).catch(err => {
            $this.markGroups = [];
        })
		},
    cx_Lchange(index, val){     //  L
      this.cx_L[index].status = val;
    },
    cus_permischange(index, val){   //  定制权益
      this.cus_primissons[index].status = val;
    },
    comPackageChange(index,val) { //  组合权益选择
      this.comPackages[index].status = val;
      const indL = this.comPackages.findIndex(item => item.name == 'L');
      if(this.comPackages[indL].status == false) {
          this.addform.cxPrimissons = [];
          this.cx_L.forEach(item => {
            item.status = false;
          })
      }
    },
    comPackageHandle() {  //  选中的
      const self_ = this
      self_.addform.comPackage = [];
      self_.addform.cxPrimissons = [];  //  畅行无忧权益范围
      self_.comPackages.forEach(item => {
        if(item.status == true) {
          self_.addform.comPackage.push(item.name);
        }
      });
      self_.cx_L.forEach(Ite => {
        if(Ite.status == true) {
          self_.addform.cxPrimissons.push(Ite.name);
        }
      });
      //  定制选中
      self_.addform.cusPrimissons = [];
      self_.cus_primissons.forEach(item => {
        if(item.status == true) {
          self_.addform.cusPrimissons.push(item.name)
        }
      });
    },
    searchHandle() {
      this.page.page = 1;
      this.currentPage = 1;
      this.initData();
    },
    //初始化请求数据
    initData() {
      this.loading = true;
      const this_ = this;
      this_.$http.get(this_.GLOBAL.REQUESTURL + "/user/getList",{
        pageNum: this_.page.page,
        pageSize: this_.page.per,
        name: this.form.name,
      })
      .then(res => {
        this_.tableData = res.data.list; //给查询列表赋值
        this_.total = res.data.total;
        this_.loading = false;
      })
      .catch(function(err) {
        this_.tableData = [];
        this_.total = 0;
        this_.loading = false;
      });
    },
    //  个人角色
    initBusHandle() {
      this.$http.get(this.GLOBAL.REQUESTURL + "/user/getRoleTypeList")
        .then(res => {
            this.d_role_types = res.data;
				})
        .catch(err => {
            this.d_role_types = [];
        })
    },
    initBusPeopHandle() {   //  业务人员-业务经理-代理
      const _this = this
        this.$http.get(this.GLOBAL.REQUESTURL + "/user/getRoleInfoList")
        .then(res => {
          const result = res.data;
            result.forEach(item => {
                if(item.roleType == '业务经理') {
                   _this.businessManagers = item.res;
                }else if(item.roleType == '业务人员') {
                    _this.businessPersonnels = item.res;
                }else if(item.roleType == '代理') {
                    _this.subordinateAgents = item.res;
                };
            })
				})
        .catch(err => {
            _this.businessManagers = [];
            _this.businessPersonnels = [];
            _this.subordinateAgents = [];
        })
    },
    // 角色权限----》封装角色名称接口函数，创建和更新操作的时候使用
    roleData(){
      var this_=this
      this_.$http.get(this_.GLOBAL.REQUESTURL + "/user/getJveesList")
      .then(res => {
        this_.groupjvese = res.data;
      }).catch(err => {
        this_.groupjvese = [];
      });
    },
    /*每页条数变化*/
    handleSizeChange(val) {
      this.page.per = val;
      this.page.page = 1;
      this.initData();
    },
    /*当前页码改变*/
    handleCurrentChange(val) {
      this.page.page = val;
      this.initData();
    },
    /*导出表格*/
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]));
    },
    /*切换状态*/
    changeStatus() {},
    /*新增用户*/
    addUser() {
      this.addTitle = "新增用户";
      this.userDisabled = false;
      this.addUserVisible = true;
      this.addform.account = "";
      this.addform.storeName = "";
      this.addform.password = "";
      this.addform.jveesId = "";
      this.addform.auditPrimissons = "0";
      this.addform.payPrimissons = "";
      this.addform.equimentPermissions = '';
      this.addform.groupId = "";
      this.addform.info = "";
      this.addform.cxPrimissons = [];
      this.addform.ybPrimissons = [];
      this.addform.comPackage = [];
      this.cx_L.forEach(item => {
        item.status = false
      });
      this.comPackages.forEach(item => {
        item.status = false
      });
      this.cus_primissons.forEach(item => {
        item.status = false
      });

      this.addform.cusPrimissons = [];
      //this.addform.development_id='';
      this.addform.isFashionable='0';
      this.rulesDisabled=true
      this.addform.fashionableRules = ''
      this.addform.roleTypesId=''
      this.addform.businessPersonnel='';
      this.addform.subordinateAgent='';
      this.addform.businessManager='';
      this.addform.comStandard = '0';
      this.addform.exeleStatus = '0';
      this.addform.dataTable = '0';
      this.addform.isL = '0';
      this.addform.comStandard1 = '';
      this.addform.comStandard2 = '';
      this.addform.comStandard3 = '';
      this.addform.comStandardC1 = '';
      this.addform.comStandardC2 = '';
      this.addform.comStandardC3 = '';
      this.addform.comStandardC4 = '';

      this.addform.projectManager = '';
      this.addform.operationSuper = '';
      this.addform.superPhone = '';
      this.addform.markGroupId = '';
      this.addform.brand = '';
      this.addform.bankofdeposit = '';
      this.addform.collection = '';
      this.customAddr = [];
      this.addform.provinces = '';
      this.addform.citys = '';
     // this.roleData();
     // this.initBusHandle();       //  个人角色
     // this.initBusPeopHandle();   //业务人员-业务经理-代理
    },
    //  开发经理
    developmentList() {
      this.$http.get(this.GLOBAL.REQUESTURL + "/user/development_list/").then(res => {
          this.developmentLists = res.msgs;
      }).catch(err => {
      })
    },
    /*获取所有集团开始*/
    getGroupIds() {
      var this_ = this;
      this_.$http.get(this_.GLOBAL.REQUESTURL + "/user/getGroupList")
      .then(res => {
        this_.groupIds = res.data;
      }).catch(err => {
        this_.groupIds = [];
      });
    },
    passChange(val) {      //  密码更改的时候
      this.addform.password = val;
    },
    /*新增提交 开始*/
    addUserSubmit(Url) {
      var that = this
      if(that.addform.cxPrimissons.length == 0 && that.addform.comPackage.length == 1 && that.addform.comPackage.includes('L')) {
        that.$message.error('请选择畅行无忧权益')
        return false
      }
      if(that.addform.cxPrimissons.length == 1 && that.addform.cxPrimissons[0] == "刮蹭无忧服务") {
        that.$message.error('不能单独选择刮蹭无忧服务')
        return false
      }
      that.comPackageHandle()
      this.$refs.addform.validate(valid => {
        if (valid) {
          const comStandards = [that.addform.comStandard1, that.addform.comStandard2 , that.addform.comStandard3];
          if(that.addform.comStandard == 1) {
            if(that.addform.comStandard1.length==0 || that.addform.comStandard2.length==0 || that.addform.comStandard3.length==0) {
              that.$message.error('请输入补偿标准')
              return false
            }
          }
          if(that.addform.isFashionable == 1) {
            if(that.addform.fashionableRules.length==0) {
                this.$message.error('分账规则不能为空')
                return false
            }
          };
          if(that.d_role_type_name == '4S店面' || that.d_role_type_name == '集团' || that.d_role_type_name == '代理') {
              if(that.addform.businessPersonnel.length == 0) {
                that.$message.error('业务人员不能为空')
                return false
              }
          };
          that.addform.password = that.addform.password == '···' ? '···' : that.getmd5(that.addform.password );
          const saveFormData = {};
          for(var key in this.addform){
              saveFormData[key] = String(this.addform[key]);
          };
          this.submitLoading = true;
          this.$http.post(that.GLOBAL.REQUESTURL + Url, saveFormData)
          .then(res => {
            if(res.code == 200) {
                that.page.page = 1;
                that.currentPage = 1;
                that.$message.success(res.msg);
                that.addUserVisible = false;
                that.submitLoading = false;
                that.initData();
            } else {
              that.$message.info(res.msg);
            };
          }).catch(err => {
            that.$message.error('操作失败!');
            that.submitLoading = false;
          });
        } else {
          this.$message.error('校验未通过!');
          return false;
        }
      });
    },
    /*新增提交 结束*/
    /*更新 开始*/
    updateUser(id) {
      var _self = this;
      _self.comPackages.forEach(item => {
        item.status = false
      });
      _self.cx_L.forEach(item => {
        item.status = false
      }); 
      _self.cus_primissons.forEach(item => {
        item.status = false
      }); 
      //$this.developmentList();
      _self.updateUserId = id;
      
      _self.addTitle = "编辑用户";
      _self.addUserVisible = true;
      _self.userDisabled = true;
      _self.rulesDisabled = true;
      this.$http.get(_self.GLOBAL.REQUESTURL + "/user/getUserInfo",{
        id: id
      }).then(res => {
          const resultData = res.data;
          const saveFormData = {};
            for(var key in resultData){
                saveFormData[key] = String(resultData[key]);
            };
          _self.addform = saveFormData;
          const arr1 = resultData.comPackage ? resultData.comPackage.split(',') : [];           //  A-L选中
          const arr2 = (resultData.cxPrimissons && resultData.comPackage.indexOf('L')!=-1) ? resultData.cxPrimissons.split(',') : [];       //  L选中的权益
          
          const arr3 = resultData.ybPrimissons ? resultData.ybPrimissons.split(',') : [];       //  延保权益
          const loss_amount = resultData.lossAmount?resultData.lossAmount.split(','):[];        //  补偿标准AB
          const loss_amountC = resultData.lossAmountC?resultData.lossAmountC.split(','):[];        //  补偿标准C
          const arr4 = resultData.cusPrimissons ? resultData.cusPrimissons.split(',') : [];       //  定制选中的权益
          _self.addform.comPackage = arr1;
          _self.addform.cxPrimissons = arr2;
          _self.addform.ybPrimissons = arr3;
          _self.addform.cusPrimissons = arr4;
          _self.addform.comStandard1 = (loss_amount[0]!='undefined' && loss_amount[0]!='null' && loss_amount!='')?loss_amount[0]:'';
          _self.addform.comStandard2 = (loss_amount[1]!='undefined' && loss_amount[1]!='null' && loss_amount!='')?loss_amount[1]:'';
          _self.addform.comStandard3 = (loss_amount[2]!='undefined' && loss_amount[2]!='null' && loss_amount!='')?loss_amount[2]:'';
           _self.addform.comStandardC1 = loss_amountC?loss_amountC[0]:'';
           _self.addform.comStandardC2 = loss_amountC?loss_amountC[1]:'';
           _self.addform.comStandardC3 = loss_amountC?loss_amountC[2]:'';
           _self.addform.comStandardC4 = loss_amountC?loss_amountC[3]:'';


          if(arr1){
              arr1.forEach(item => {
                const index = _self.comPackages.findIndex(Ite => Ite.name == item);
                if(index==-1) {return}
                _self.comPackages[index].status = true;
              });
          };
          if(arr2) {
              arr2.forEach(item => {
                const index2 = _self.cx_L.findIndex(Ite => Ite.name == item);
                if(index2==-1) {return}
                _self.cx_L[index2].status = true;
              })
          };
          if(arr4) {
              arr4.forEach(item => {
                const index4 = _self.cus_primissons.findIndex(Ite => Ite.name == item);
                if(index4==-1) {return}
                index4 != -1 ? _self.cus_primissons[index4].status = true : '';
              })
          };
          _self.customAddr = resultData.provinces?[resultData.provinces,resultData.citys]:[];
      }).catch(err => {
          _self.$message.info('数据获取失败！')
      });
    },
    /*更新 结束*/
    
    //  获取定制权益价格
    cusPriceHandle(id) {
      const this_ = this
      this_.priceLoading = true;
      this_.activeName = 'first';
      this_.priceId = id;
      this.$http.get(this.GLOBAL.REQUESTURL+'/user/getCusPrice?userId='+id)
      .then(res => {
        if(res.code == 200) {
          this_.priceVisible = true
          this_.priceTableData_cus = res.data;
        } else {
          this_.$message.info(res.msg);
        };
        this_.priceLoading = false;
      }).catch(err => {
        this_.priceTableData_cus = [];
        this_.priceLoading = false;
      })
    },
    //  获取畅行权益价格
    cxPriceHandle(id) {
      const this_ = this
      this_.priceLoading_cx = true;
      this.$http.get(this.GLOBAL.REQUESTURL+'/user/getCxPrice?userId='+id)
      .then(res => {
        if(res.code == 200) {
          this_.priceTableData_cx = res.data;
        } else {
          this_.$message.info(res.msg);
        };
        this_.priceLoading_cx = false;
      }).catch(err => {
        this_.priceTableData_cx = [];
        this_.priceLoading_cx = false;
      })
    },
    priceSubmit_cus() {       //  定制权益价格提交
      const _self = this
      this.$refs.priceform.validate(valid => {
        if (valid) {
            _self.$http.post(_self.GLOBAL.REQUESTURL + '/user/saveCusPrice', {
              userId: _self.priceId,
              req: _self.priceTableData_cus
            })
            .then(res => {
              if(res.code == 200) {
                _self.$message.success(res.msg);
                _self.priceVisible = false;
                _self.initData();
              } else {
                _self.$message.info(res.msg);
              }

            }).catch(err => {
                 _self.$message.error('操作失败！');
                 _self.priceVisible = false;
            })
        }else {
          return false
        }
      })
    },
    priceSubmit_cx() {      //   畅行权益价格提交
      const __self = this
      __self.$http.post(__self.GLOBAL.REQUESTURL + '/user/saveCxPrice', {
          userId: __self.priceId,
          req: __self.priceTableData_cx
      }).then(res => {
        if(res.code == 200) {
          __self.$message.success(res.msg);
          __self.priceVisible = false;
          __self.initData();
        } else {
          __self.$message.info(res.msg);
        }

      }).catch(err => {
          __self.$message.error('操作失败！');
          __self.priceVisible = false;
      });
    },
    //  修改价格  end

    /*删除 开始*/
    deleteUser(item) {
      var $this = this;
      this.$confirm("确认删除 "+ item.username +" 该用户?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.axios({
            method: "delete",
            /*headers:{
							'Authorization':$this.GLOBAL.TOKEN,
					  	},*/
            url: $this.GLOBAL.REQUESTURL + "/user/register/" + item.id + "/"
          })
            .then(function(res) {
              $this.$message({
                type: "success",
                message: "删除成功!"
              });
              $this.initData();

            })
            .catch(function(err) {
            });
        })
        .catch(err => {
          $this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    validChange() {        
     // this.$refs.addform.clearValidate();
     this.addform.fashionableRules = ''
     if(this.addform.isFashionable==1) {
       this.$message.error('请输入分账规则')
       this.rulesDisabled = false
     }else{
       this.rulesDisabled = true
     }
    }
    /*删除 结束*/
  },
  mounted() {
    this.$nextTick(function() {
      if(localStorage.getItem("token")) { 
        this.initData();
        this.getGroupIds(); 
        this.roleData();             //  角色权限
        this.initBusHandle();       //  个人角色
        this.initBusPeopHandle();   //业务人员-业务经理-代理
        this.carBrand()
        this.markGroupsHandle()
      };
    });
   
  },
};
</script>

<style scoped>
.registerMargin {
  margin-left: 30px;
}
.top_row {
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.box-card .el-card__header {
  text-align: left;
  border-bottom: none;
}
.box-card .text label {
  display: block;
}
.box-card .text .font_bold {
  font-weight: bold;
  margin-top: 8px;
}
.el-form--inline .el-form-item {
  float: left;
}
.footer {
  width: 100%;
  text-align: center;
}
.el-form--inline .el-form-item {
  margin-bottom: 20px;
}
.regStyle{
  width: 100% !important;
}
.regStyle textarea{
  height: 40px;
}
.regStyle .el-form-item__content{
  width: 60% !important;
}
.userGroup{
  width: 100%;
}
.registerModal /deep/ .el-col{
  text-align:left;
}
.registerModal /deep/ .el-form-item.cxPrimissons {
  padding-left: 18px;
}
.registerModal /deep/ .el-form-item.cxPrimissons .el-form-item__content{
  padding-left: 20px;
}
.comStandard td, .comStandard th{
  text-align:center;
}
.el-table.comStandard::before {
  height: 0;
}
.comStandard .el-input__inner {
  height: 30px;
}
.comStandard .el-form-item__content {
  height: 30px;
  line-height: 30px;
}
.el-cascader .el-input .el-input__inner {
  height: 40px;
}
.el-cascader {
  width: 100%;
}
.priceTitle {
  text-align: left;
  padding: 0px 40px 10px 40px;
}
.priceTable th {
  background: none;
}
.el-table.priceTable td, .el-table th.is-leaf {
  background: none !important;
}
td .el-input {
  margin: 2px 0;
}
</style>
